#pragma once

#include <vector>
#include ".\cmpp_base.h"
#include <afxmt.h>
#include "afxmt.h"
#include ".\sendinfo.h"
#include ".\publicfun.h"

using namespace std;

class SendPool
{
public:
	SendPool(void);
	~SendPool(void);
private:
	unsigned int _serialNo;
	unsigned int _sendNo;
public:
	unsigned int ActiveSpan;
	unsigned int RetrySpan;
	unsigned int CacheSize;
	unsigned int TryTimes;
private:
	vector<SendInfo *> submitlist;
	vector <Cmpp_Base *> resplist;
	CCriticalSection subMutex;
	CCriticalSection respMutex;
	CSemaphore * sem;
	CTime lastsend;

	Cmpp_Submit * GetNeedSub(void);
	Cmpp_Base * GetNeedResp(void);

	string AddWapSMS(string info, byte needreport, byte level, string serviceid, byte feeusertype, string feeterminalid, string msgsrc, string feetype, string feecode, string validtime, string attime, string srcid, string destterminalid);

public:
	void AddResponse(Cmpp_Base * pack);
	string AddNormalSMS(string str, byte needreport, byte level, string serviceid, byte feeusertype, string feeterminalid, string msgsrc, string feetype, string feecode, string validtime, string attime, string srcid, string destterminalid);
	string AddSparkSMS(string str, byte needreport, byte level, string serviceid, byte feeusertype, string feeterminalid, string msgsrc, string feetype, string feecode, string validtime, string attime, string srcid, string destterminalid);
	string AddWapPushSMS(string str, string url, byte needreport, byte level, string serviceid, byte feeusertype, string feeterminalid, string msgsrc, string feetype, string feecode, string validtime, string attime, string srcid, string destterminalid);
	string AddMMSIndication(string url, string disptelno, byte needreport, byte level, string serviceid, byte feeusertype, string feeterminalid, string msgsrc, string feetype, string feecode, string validtime, string attime, string srcid, string destterminalid);
	Cmpp_Active_Test * GetActiveTest(void);
	Cmpp_Terminate * GetTerminate(void);
	Cmpp_Connect * GetConnect(void);
	Cmpp_Base * GetNeedSend(void);
	void Start(void);
	void Stop(void);
	bool SucceedSMS(unsigned int serialno, unsigned int *sendno, bool *isfinish);
	bool ErrorSMS(unsigned int serialno, unsigned int *sendno, bool *isfinish);
	void Reset(void);
	void RestoreSubTime(unsigned int serialno);
};
